package io.renren.modules.yst.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.common.utils.Constant;
import io.renren.modules.sys.controller.AbstractController;
import io.renren.modules.yst.vo.CheckRecordVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.yst.entity.WorkerCardRecordEntity;
import io.renren.modules.yst.service.WorkerCardRecordService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 运输工作单
 *
 * @author lazyrm
 * @email lazyrm0720@gmail.com
 * @date 2022-01-07 21:01:22
 */
@RestController
@RequestMapping("yst/workercardrecord")
public class WorkerCardRecordController extends AbstractController {
    @Autowired
    private WorkerCardRecordService workerCardRecordService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("yst:workercardrecord:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = workerCardRecordService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @RequestMapping("/listrecord")
    public R listrecord(@RequestParam Map<String, Object> params) {

        long curPage = 1;
        long limit = 10;

        if(params.get(Constant.PAGE) != null){
            curPage = Long.parseLong((String)params.get(Constant.PAGE));
        }
        if(params.get(Constant.LIMIT) != null){
            limit = Long.parseLong((String)params.get(Constant.LIMIT));
        }



        QueryWrapper<CheckRecordVo> queryWrapper = new QueryWrapper<CheckRecordVo>();

        if(params.get("carNumber") != null){
            queryWrapper.like("t2.car_number",params.get("carNumber"));
        }

        Page<CheckRecordVo> page= new Page<CheckRecordVo>(  curPage,limit);
        //自定义getAll接口
        PageUtils result = workerCardRecordService.queryPageForManager(page, queryWrapper.eq("manager_id", getUserId()));



        return R.ok().put("page", result);
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{recordId}")
    @RequiresPermissions("yst:workercardrecord:info")
    public R info(@PathVariable("recordId") Long recordId){
		WorkerCardRecordEntity workerCardRecord = workerCardRecordService.getById(recordId);

        return R.ok().put("workerCardRecord", workerCardRecord);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("yst:workercardrecord:save")
    public R save(@RequestBody WorkerCardRecordEntity workerCardRecord){
		workerCardRecordService.save(workerCardRecord);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("yst:workercardrecord:update")
    public R update(@RequestBody WorkerCardRecordEntity workerCardRecord){
		workerCardRecordService.updateById(workerCardRecord);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("yst:workercardrecord:delete")
    public R delete(@RequestBody Long[] recordIds){
		workerCardRecordService.removeByIds(Arrays.asList(recordIds));

        return R.ok();
    }

}
